#include <iostream>
using namespace std;
 
const int N = 1e5 + 10;
int n;
int arr[N];
 
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int ret = 0, prevMin = arr[0];
    for(int i = 1; i < n; i++)
    {
        prevMin = min(arr[i], prevMin);
        ret = max(ret, arr[i] - prevMin);
    }
    cout << ret << endl;
    return 0;
}